package com.sinosoft.utils;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * 腾讯位置服务统一工具类
 * @Author: WangShengJie
 * @Date: 2025/2/19
 */
public class TencentMapUtils {

//    private static final Logger logger = LoggerFactory.getLogger(TencentMapUtils.class);

    public static String paramFormat(Map<String,String> param) {
//        logger.info("paramFormat：入参：{}", param);
        //遍历Map
        if (ObjectUtils.isEmpty(param)) {
            return null;
        }
        StringBuffer rePara = new StringBuffer();
        try {
            rePara.append("?");
            List<String> keyList = new ArrayList<>();
            for (Map.Entry<String, String> entry : param.entrySet()) {
                keyList.add(entry.getKey());
            }
            //根据首字母排序,目前没有忽略大小写
            Collections.sort(keyList);
            for (String key : keyList) {
                rePara.append(key);
                if (StringUtils.isEmpty(param.get(key))) {
//                    logger.info("paramFormat：未获取到该key对应value；key:{}",key);
                    return null;
                }
                rePara.append("=" + param.get(key).toString());
                rePara.append("&");
            }
            String finalParam = rePara.toString().substring(0, rePara.toString().length() - 1);
//            logger.info("paramFormat：拼接完的参数为：{}",finalParam);
            return finalParam;
        } catch (Exception e) {
//            logger.error("paramFormat：参数拼接失败~~", e);
        }
        return null;
    }

    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("id", "1515,12345");
        map.put("app", "kfodjf");
        map.put("zkj", "5555");
        map.put("IDD", "8999");
        map.put("key", "445454545");
        String s = paramFormat(map);
        System.out.println(s);

    }

}
